package demo;

public class Text {

    public static void main6(String[] args) {
        System.out.println(Student.ClassRoom);                 //java01 (静态方法不依赖对象可以直接打印,静态代码块位置在静态成员变量之后,使其初始化的值java被java01覆盖)

        Student student1 = new Student();                      //对象1 static执行
        System.out.println("-----------------");
        Student student2 = new Student();                      //对象2 static不执行了
    }

    public static void main5(String[] args) {                  //构造方法带有参数同样是先执行实例代码块
        Student student1 = new Student("悟空",100);
        System.out.println(student1.name);                     //由于先执行实例代码块后执行构造方法导致名字bit被悟空覆盖掉
        System.out.println(student1.age);
        System.out.println("--------------");
        Student student2 = new Student("八戒",100);
        System.out.println(student2.name);
        System.out.println(student2.age);

    }

    public static void main4(String[] args) {   //构造方法无参数同样是先执行实例代码块
        Student student1 = new Student();
        System.out.println(student1.name);      //bit 无实例化代码块时为：null
        System.out.println(student1.age);       //6   无实例化代码块时为：0
    }

    //代码块
    public static void main3(String[] args) {
        //普通代码块：定义在方法中，直接使用{}来定义
        {
            int a1 = 10;
            System.out.println("a1 = " + a1);
        }
        int a2 = 100;
        System.out.println("a2 = " + a2);
    }



    public static void main2(String[] args) {
        Student.ClassRoom = "java117";
        System.out.println(Student.ClassRoom);       //静态成员变量(类变量)，存储在方法区全局只有一份，随类生成被调用，随类销毁而销毁

        System.out.println(Student.getClassRoom());  //静态成员方法的访问也是类名+点号
    }

    public static void main1(String[] args) {
        Student student1 = new Student();
        student1.name = "zhangsan";
        student1.age = 13;
        //student1.ClassRoom = "java117";       //被static修饰时使用引用+点号访问不会报错但是不合理
        Student.ClassRoom = "java117";          //被static修饰的静态成员变量使用类名+点号进行访问


        Student student2 = new Student();
        student2.name = "wangwu";
        student2.age = 15;

        System.out.println(Student.ClassRoom);
    }
}
